package cn.org.book.shop.article.service.impl;

import cn.org.book.shop.article.domain.ApArticle;
import cn.org.book.shop.article.domain.ApUserChannel;
import cn.org.book.shop.article.mapper.ApArticleMapper;
import cn.org.book.shop.article.mapper.ApUserChannelMapper;
import cn.org.book.shop.article.service.IApUserChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * APP用户频道信息Service业务层处理
 *
 * @author julywhj
 * @date 2020-11-17
 */
@Service
public class ApUserChannelServiceImpl implements IApUserChannelService {
    @Resource
    private ApUserChannelMapper apUserChannelMapper;

    @Resource
    private ApArticleMapper apArticleMapper;

    /**
     * 查询APP用户频道信息
     *
     * @param id APP用户频道信息ID
     * @return APP用户频道信息
     */
    @Override
    public ApUserChannel selectApUserChannelById(Long id) {
        return apUserChannelMapper.selectApUserChannelById(id);
    }

    /**
     * 查询APP用户频道信息列表
     *
     * @param apUserChannel APP用户频道信息
     * @return APP用户频道信息
     */
    @Override
    public List<ApUserChannel> selectApUserChannelList(ApUserChannel apUserChannel) {
        List<ApUserChannel> apUserChannels = apUserChannelMapper.selectApUserChannelList(apUserChannel);
        apUserChannels.forEach(channel -> {
            ApArticle apArticle = new ApArticle();
            apArticle.setChannelId(channel.getId());
            channel.setArticleNumber(apArticleMapper.selectApArticleList(apArticle).size());
        });
        return apUserChannels;
    }

    /**
     * 新增APP用户频道信息
     *
     * @param apUserChannel APP用户频道信息
     * @return 结果
     */
    @Override
    public int insertApUserChannel(ApUserChannel apUserChannel) {
        return apUserChannelMapper.insertApUserChannel(apUserChannel);
    }

    /**
     * 修改APP用户频道信息
     *
     * @param apUserChannel APP用户频道信息
     * @return 结果
     */
    @Override
    public int updateApUserChannel(ApUserChannel apUserChannel) {
        return apUserChannelMapper.updateApUserChannel(apUserChannel);
    }

    /**
     * 批量删除APP用户频道信息
     *
     * @param ids 需要删除的APP用户频道信息ID
     * @return 结果
     */
    @Override
    public int deleteApUserChannelByIds(Long[] ids) {
        return apUserChannelMapper.deleteApUserChannelByIds(ids);
    }

    /**
     * 删除APP用户频道信息信息
     *
     * @param id APP用户频道信息ID
     * @return 结果
     */
    @Override
    public int deleteApUserChannelById(Long id) {
        return apUserChannelMapper.deleteApUserChannelById(id);
    }
}
